package cn.edu.zut.project1.mapper;

import cn.edu.zut.project1.pojo.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.core.annotation.Order;

import java.util.List;
@Mapper
public interface OrdersMapper {

    // 1. 创建订单（下单）
    @Insert("insert into orders (" +
            "order_no, product_id, product_name, buyer_id, seller_id, " +
            "price, status, create_time" +
            ") values (" +
            "#{orderNo}, #{productId}, #{productName}, #{buyerId}, #{sellerId}, " +
            "#{price}, #{status}, now()" +
            ")")
    int insert(Orders orders);

    // 2. 根据订单编号查询订单
    @Select("select * from orders where order_no = #{orderNo}")
    Orders selectByOrderNo(String orderNo);

    // 3. 更新订单状态（付款/发货/确认收货/取消）
    @Update("update orders set " +
            "status = #{status}, " +
            "pay_time = #{payTime}, " +
            "finish_time = #{finishTime} " +
            "where id = #{id}")
    int updateStatus(Orders orders);

    // 4. 查询买家的订单列表（我的订单）
    @Select("select * from orders where buyer_id = #{buyerId} order by create_time desc")
    List<Orders> selectByBuyerId(Integer buyerId);

    // 5. 查询卖家的订单列表（卖给我的订单）
    @Select("select * from orders where seller_id = #{sellerId} order by create_time desc")
    List<Orders> selectBySellerId(Integer sellerId);

    // 6.查询我作为买家的订单
    @Select("select * from orders where buyer_id = #{buyerId}")
    List<Orders> selectAsBuyerOrders(Integer buyerId);

    // 7.查询我作为卖家的订单
    @Select("select * from orders where seller_id = #{sellerId}")
    List<Orders> selectAsSellerOrders(Integer sellerId);
}



